package com.kestrel.space.common.utils;

import lombok.Getter;

/**
 * @author yebolin
 * @date 2024/8/21
 */
@Getter
public class BizException extends RuntimeException {
    private static final long serialVersionUID = -2991132952492537631L;
    private final String code;
    private final String simpleMessage;
    private Object data;

    public BizException(String code) {
        this(code, (String)null, (Throwable)null);
    }

    public BizException(String code, String message) {
        this(code, message, (Throwable)null);
    }

    public BizException(String message, Throwable cause) {
        this("500", message, cause);
    }

    public BizException(String code, String message, Throwable cause) {
        this(code, message, message, cause);
    }

    public BizException(String code, String message, String simpleMessage, Throwable cause) {
        super(message, cause);
        this.code = code;
        this.simpleMessage = simpleMessage;
    }

    public BizException(ResultMessage resultMessage) {
        this(resultMessage.getCode(), resultMessage.getMessage(), (Throwable)null);
    }

    public BizException(ResultMessage resultMessage, Object data) {
        this(resultMessage.getCode(), resultMessage.getMessage(), (Throwable)null);
        this.data = data;
    }

    public String toString() {
        return "[" + this.code + "]:" + this.getMessage();
    }

}
